package edu.siu.math.egut.util;

import java.util.ArrayList;
import java.util.Arrays;


public class Piece {

    private static final ArrayList<Piece> listOfKnownPieces = new ArrayList<Piece>();
    private final Parabolic parabolic;
    private final int[] specifier;
    
    private Piece(Parabolic givenP, int[] givenSpecifier){
	parabolic = givenP;
	specifier = givenSpecifier;
    }
    
    public static Piece create( Parabolic givenP, int[] givenSpecifier){
	for(Piece p: listOfKnownPieces){
	    if(p.parabolic == givenP && Arrays.equals(givenSpecifier, p.specifier))
		return p;
	    
	}
	Piece newPiece = new Piece(givenP, givenSpecifier);
	listOfKnownPieces.add(newPiece);
	return newPiece;
    }

    public static Piece create(Parabolic p, String string) {
	int [] tuple = edu.siu.math.egut.io.Algorithms.tupleFromString(string);
	if(tuple.length != p.getCorank() )
	    return null;
	return Piece.create(p, tuple);
    }
    
}
